package examples

import (
	"HumaTemplate/internal/models"
	"HumaTemplate/internal/models/examples"
	"context"
	"github.com/danielgtaylor/huma/v2"
)

var (
	prefix = "/users"
	tags   = []string{"users"}
)

func Init(api huma.API) {
	huma.Get(api, prefix, func(ctx context.Context, i *struct{}) (*models.HumaResponse[models.GenericListData[examples.User]], error) {
		return &models.HumaResponse[models.GenericListData[examples.User]]{}, nil
	}, func(o *huma.Operation) {
		o.Summary = "获取用户"
		o.Tags = tags
	})

	huma.Get(api, prefix+"/:id", func(ctx context.Context, i *struct {
		Id int `path:"id"`
	}) (*models.HumaResponse[models.GenericData[examples.User]], error) {
		return &models.HumaResponse[models.GenericData[examples.User]]{}, nil
	}, func(o *huma.Operation) {
		o.Summary = "获取用户"
		o.Tags = tags
	})

	huma.Post(api, prefix, func(ctx context.Context, i *struct{}) (*models.HumaResponse[models.GenericData[examples.User]], error) {
		return &models.HumaResponse[models.GenericData[examples.User]]{}, nil
	}, func(o *huma.Operation) {
		o.Summary = "创建用户"
		o.Tags = tags
	})

	huma.Put(api, prefix+"/:id", func(ctx context.Context, i *struct {
		Id int `path:"id"`
	}) (*models.HumaResponse[models.GenericData[examples.User]], error) {
		return &models.HumaResponse[models.GenericData[examples.User]]{}, nil
	}, func(o *huma.Operation) {
		o.Summary = "更新用户"
		o.Tags = tags
	})

	huma.Delete(api, prefix+"/:id", func(ctx context.Context, i *struct {
		Id int `path:"id"`
	}) (*models.HumaResponse[models.GenericData[examples.User]], error) {
		return &models.HumaResponse[models.GenericData[examples.User]]{}, nil
	}, func(o *huma.Operation) {
		o.Summary = "删除用户"
		o.Tags = tags
	})
}
